package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.framework.core.result.APIObjResponse;
import com.framework.core.result.BasePage;
import com.project.base.BaseController;
import com.project.biz.*;
import com.project.common.model.UserInfo;
import com.project.common.utils.IpageToPage;
import com.project.entity.CmsUser;
import com.project.pojo.dto.TuserDTO;
import com.project.pojo.dto.UserDTO;
import com.project.pojo.dto.UserLoginDTO;
import com.project.pojo.dto.UserLoginPcDTO;
import com.project.pojo.model.*;
import com.project.pojo.vo.UserLoginVO;
import com.project.pojo.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.Date;
import java.util.UUID;


/**
* @Description:   用户
* @Author:         wangzhiqiang
* @CreateDate:     2019-02-27 9:31
* @Version:        1.0
*/
@Api(value = "UserController", description = "用户")
@Slf4j
@RestController
@RequestMapping(value = "/user")
public class CmsUserController extends BaseController {

    /**
     * 用户
     */
    @Autowired
    private UserBiz userBiz;

    /**
     * 用户缓存信息
     */
    @Autowired
    private RedisBiz redisBiz;

    /**
     * Redis统计信息缓存
     */
    @Autowired
    private RedisBiz2 redisBiz2;

    /**
     * 操作日志
     */
    @Autowired
    private CmsOperationLogBiz operationLogBiz;

    /**
     * 国际化
     */
    @Autowired
    private I18nBiz i18nBiz;

    /**
     * 用户余额
     */
    @Autowired
    private CmsUserBalanceBiz userBalanceBiz;

    /**
     * 用户登录（根据密码登录）
     * @param userLoginPcDTO
     * @return
     */
    @ApiOperation(value = "用户登录（根据密码登录）", httpMethod = "POST")
    @PostMapping(value = "/login")
    public APIObjResponse<UserLoginVO> login(@Validated @RequestBody UserLoginPcDTO userLoginPcDTO){
        UserLoginVO userLoginVO = this.userBiz.login(userLoginPcDTO, super.getHttpServletRequest());

        if (null != userLoginVO){
            this.redisBiz.setUserInfo(userLoginVO.getToken(), userLoginVO.getBaseUserId());
        }

        if (null != userLoginVO) return APIObjResponse.success(this.i18nBiz.getMessage("msg.successfullyLogin"), userLoginVO);
        return APIObjResponse.success(this.i18nBiz.getMessage("msg.failedToLogin"));
    }

    /**
     * 用户登录（根据验证码登录）
     * @param userLoginDTO
     * @return
     */
    @ApiOperation(value = "用户登录（根据验证码登录）", httpMethod = "POST")
    @PostMapping(value = "/userLogin")
    public APIObjResponse<UserLoginVO> userLogin(@Validated @RequestBody UserLoginDTO userLoginDTO){
        UserLoginVO userLoginVO = this.userBiz.userLogin(userLoginDTO);

        if (null != userLoginVO){
            this.redisBiz.setUserInfo(userLoginVO.getToken(), userLoginVO.getBaseUserId());
        }

        if (null != userLoginVO){
            //成功后清空缓存的二维码
            this.userBiz.delVerifyCode(userLoginDTO.getMobile());
            return APIObjResponse.success(this.i18nBiz.getMessage("msg.successfullyLogin"), userLoginVO);
        }
        return APIObjResponse.success(this.i18nBiz.getMessage("msg.failedToLogin"));
    }

    /**
     * 获取注册令牌,用于获取图形验证码
     * @return
     */
    @GetMapping(value = "/getRegisterKey")
    public APIObjResponse<String> getRegisterKey(){
        //生成随机字符串
        String registerKey = UUID.randomUUID().toString();
        return APIObjResponse.success(this.i18nBiz.selectSuccessMessage(), registerKey);
    }

    /**
     * 注册
     * @return
     */
    @ApiOperation(value = "用户注册", httpMethod = "POST")
    @PostMapping(value = "/userRegister")
    public APIObjResponse<Integer> userRegister(HttpServletRequest request, @Validated @RequestBody UserRegisterModel userRegisterModel){
        log.info("注册入参:" + userRegisterModel);
        //注册功能维护中
//        return APIObjResponse.error(this.i18nBiz.getMessage("msg.registrationMaintenance"));
        //验证注册令牌
        boolean checkRegisterImgCode = this.redisBiz.checkRegisterImgCode(userRegisterModel.getRegisterKey());
        //没有注册令牌
        if (checkRegisterImgCode == false){
            return APIObjResponse.error(this.i18nBiz.getMessage("msg.registerKey"));
        }

        //获取Redis中的图形验证码
        String img_code = this.redisBiz.getRegisterImgCode(userRegisterModel.getRegisterKey());

        //图形验证码不正确
        if (!img_code.equals(userRegisterModel.getImgCode())){
            return APIObjResponse.error(this.i18nBiz.getMessage("msg.ImgCodeIncorrect"));
        }

        int result = this.userBiz.userRegister(userRegisterModel);

        //删除注册令牌对应的图形验证码
        this.redisBiz.delRegisterImgCode(userRegisterModel.getRegisterKey());

        //使用手机验证码验证
//        //缓存中的验证码
//        String caCode = this.userBiz.findCodeById(userRegisterModel.getMobile());
//
//        if (null == caCode || !caCode.equals(String.valueOf(userRegisterModel.getCode()))){
//            return APIObjResponse.error(this.i18nBiz.getMessage("msg.incorrectVerificationCode"));
//        }
//        int result = this.userBiz.userRegister(userRegisterModel);
//        if (result == 1){
//            //注册成功后清空缓存的二维码
//            this.userBiz.delVerifyCode(userRegisterModel.getMobile());
//        }
        return APIObjResponse.success(this.i18nBiz.getMessage("msg.successfullyRegistered"), result);
    }

    /**
     * 获取当前登录用户信息
     * @return
     */
    @ApiOperation(value = "获取当前登录用户基本信息")
    @GetMapping(value = "/getLoginUserInfo")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = UserVO.class)})
    public APIObjResponse<UserVO> getLoginUserInfo(){
        UserInfo userInfo = super.getLoginUser();

        UserVO userVO = new UserVO();
        CmsUser user = this.userBiz.getById(userInfo.getBaseUserId());

        BeanUtils.copyProperties(user, userVO);

        //获取用户余额
        BigDecimal userBalance = this.userBalanceBiz.getUserBalance(userInfo.getBaseUserId());
        userVO.setBalance(userBalance);

        return APIObjResponse.success(this.i18nBiz.selectSuccessMessage(), userVO);
    }

    /**
     * 根据用户ID获取用户信息
     * @return
     */
    @ApiOperation(value = "根据用户ID获取用户信息")
    @GetMapping(value = "/getUserInfoById")
    public APIObjResponse<UserVO> getUserInfoById(@RequestParam("baseUserId") Long baseUserId){
        UserVO userVO = new UserVO();
        CmsUser user = this.userBiz.getById(baseUserId);

        BeanUtils.copyProperties(user, userVO);
        //获取用户余额
        BigDecimal userBalance = this.userBalanceBiz.getUserBalance(user.getBaseUserId());
        userVO.setBalance(userBalance);

        return APIObjResponse.success(this.i18nBiz.selectSuccessMessage(), userVO);
    }

    /**
     * 分页查询用户列表
     * @return
     */
    @ApiOperation(value = "分页查询用户列表")
    @PostMapping(value = "/getUsers")
    public APIObjResponse<BasePage<UserDTO>> getUsers(@RequestBody UserQuery userQuery){
        IPage<UserDTO> iPage = this.userBiz.selectUserByQuery(userQuery);
        BasePage<UserDTO> basePage = IpageToPage.toBasePage(iPage, UserDTO.class);
        return APIObjResponse.success(this.i18nBiz.selectSuccessMessage(), basePage);
    }

    /**
     * 代理查询用户列表
     * 默认查询当前代理用户的下级用户
     * @return
     */
    @ApiOperation(value = "代理查询用户列表")
    @PostMapping(value = "/getAgentUsers")
    public APIObjResponse<BasePage<UserDTO>> getAgentUsers(@RequestBody UserQuery userQuery){
        UserInfo user = super.getLoginUser();
        if (null == userQuery.getParentId()){
            userQuery.setParentId(user.getBaseUserId());
        }
        IPage<UserDTO> iPage = this.userBiz.getAgentUsers(userQuery);
        BasePage<UserDTO> basePage = IpageToPage.toBasePage(iPage, UserDTO.class);
        return APIObjResponse.success(this.i18nBiz.selectSuccessMessage(), basePage);
    }

    /**
     * 退出登录
     * @return
     */
    @ApiOperation(value = "退出登录", httpMethod = "GET")
    @GetMapping(value = "/loginOut")
    public APIObjResponse<String> loginOut(HttpServletResponse response){
        this.redisBiz.loginOut(super.getToken());
        return APIObjResponse.success(this.i18nBiz.getMessage("msg.successfullyLogout"));
    }

    /**
     * 修改个人信息
     * @param updateUserModel
     * @return
     */
    @ApiOperation(value = "修改个人信息, 返回信息(1:成功,0:失败)")
    @PostMapping(value = "/updateUserInfo")
    public APIObjResponse<Integer> updateUserInfo(@RequestBody UpdateUserModel updateUserModel){
        UserInfo user = super.getLoginUser();
        Integer result = this.userBiz.updateUserInfo(updateUserModel, user.getBaseUserId());
        return APIObjResponse.success(this.i18nBiz.operationSuccessMessage(), result);
    }

    /**
     * 设置支付密码
     * @param updatePayPasswordModel
     * @return
     */
    @ApiOperation(value = "设置支付密码, 返回信息(1:成功,0:失败)")
    @PostMapping(value = "/updatePayPassword")
    public APIObjResponse<Integer> updatePayPassword(@Validated @RequestBody UpdatePayPasswordModel updatePayPasswordModel){
        if (!updatePayPasswordModel.getPayPassword1().equals(updatePayPasswordModel.getPayPassword2())){
            return APIObjResponse.error(this.i18nBiz.getMessage("msg.bothPasswordEntriesAreVarying"));
        }
        UserInfo user = super.getLoginUser();
        Integer result = this.userBiz.updatePayPassword(updatePayPasswordModel, user.getBaseUserId());
        return APIObjResponse.success(this.i18nBiz.operationSuccessMessage(), result);
    }

    /**
     * 修改支付密码
     * @param editPayPasswordModel
     * @return
     */
    @ApiOperation(value = "修改支付密码, 返回信息(1:成功,0:失败)")
    @PostMapping(value = "/editPayPassword")
    public APIObjResponse<Integer> editPayPassword(@Validated @RequestBody EditPayPasswordModel editPayPasswordModel){
        if (StringUtils.isBlank(editPayPasswordModel.getCode())){
            return APIObjResponse.error(this.i18nBiz.getMessage("msg.verificationCodeMustBeFilled"));
        }
        UserInfo userInfo = super.getLoginUser();
        CmsUser user = this.userBiz.getById(userInfo.getBaseUserId());
        //缓存中的验证码
        String caCode = this.userBiz.findCodeById(user.getMobile());

        if (null == caCode || !caCode.equals(String.valueOf(editPayPasswordModel.getCode()))){
            return APIObjResponse.error(this.i18nBiz.getMessage("msg.incorrectVerificationCode"));
        }

        int result = this.userBiz.editPayPassword(editPayPasswordModel, user.getBaseUserId());
        if (result == 1){
            //成功后清空缓存的二维码
            this.userBiz.delVerifyCode(user.getMobile());
        }
        return APIObjResponse.success(this.i18nBiz.operationSuccessMessage(), result);
    }

    /**
     * 修改支付密码（根据登录密码验证）
     * @param editPayPasswordByLoginModel
     * @return
     */
    @ApiOperation(value = "修改支付密码（根据登录密码验证）, 返回信息(1:成功,0:失败)")
    @PostMapping(value = "/editPayPasswordByLogin")
    public APIObjResponse<Integer> editPayPasswordByLogin(@Validated @RequestBody EditPayPasswordByLoginModel editPayPasswordByLoginModel){
        log.info("修改支付密码（根据登录密码验证）入参：" + editPayPasswordByLoginModel);
        UserInfo userInfo = super.getLoginUser();
        int result = this.userBiz.editPayPasswordByLogin(editPayPasswordByLoginModel, userInfo.getBaseUserId());
        return APIObjResponse.success(this.i18nBiz.operationSuccessMessage(), result);
    }

    /**
     * 修改头像
     * @param portrait
     * @return
     */
    @ApiOperation(value = "修改头像, 返回信息(1:成功,0:失败)")
    @GetMapping(value = "/updatePortrait")
    public APIObjResponse<Integer> updatePortrait(@RequestParam("portrait") String portrait){
        CmsUser user = this.userBiz.getById(super.getLoginUser().getBaseUserId());
        user.setWxPortrait(portrait);
        boolean result = this.userBiz.updateById(user);
        return APIObjResponse.success(this.i18nBiz.operationSuccessMessage(), result ? 1 : 0);
    }

    /**
     * 发送验证码
     * @param mobile
     * @return
     */
    @ApiOperation(value = "发送验证码")
    @GetMapping(value = "/getValidateCode")
    public APIObjResponse<String> getValidateCode(@RequestParam("mobile") String mobile){
        //验证码放入缓存
        String code = this.userBiz.saveVerifyCode(mobile);

        //发送短信
        boolean result = true;//this.userBiz.sendValidateCode(mobile, code);

        if (result){
            return APIObjResponse.success(this.i18nBiz.getMessage("msg.successfullySendVerificationCode"), code);
        }else {
            return APIObjResponse.error(this.i18nBiz.getMessage("msg.failedSendVerificationCode"));
        }
    }

    /**
     * 修改密码
     * @param updatePasswordModel
     * @return
     */
    @ApiOperation(value = "修改密码, 返回信息(1:成功,0:失败)")
    @PostMapping(value = "/updatePassword")
    public APIObjResponse<Integer> updatePassword(@Validated @RequestBody UpdatePasswordModel updatePasswordModel){
        log.info("修改密码入参:" + updatePasswordModel);
        UserInfo userInfo = super.getLoginUser();
        CmsUser user = this.userBiz.getById(userInfo.getBaseUserId());
        //缓存中的验证码
        String caCode = this.userBiz.findCodeById(user.getMobile());

        if (null == caCode || !caCode.equals(String.valueOf(updatePasswordModel.getCode()))){
            return APIObjResponse.error(this.i18nBiz.getMessage("msg.incorrectVerificationCode"));
        }
        int result = this.userBiz.updatePassword(updatePasswordModel, user.getBaseUserId());
        if (result == 1){
            //成功后清空缓存的二维码
            this.userBiz.delVerifyCode(user.getMobile());
        }
        return APIObjResponse.success(this.i18nBiz.operationSuccessMessage(), result);
    }

    /**
     * 根据旧密码修改密码
     * @param updatePasswordByPasswordModel
     * @return
     */
    @ApiOperation(value = "根据旧密码修改密码")
    @PostMapping(value = "/updatePasswordByOldPassword")
    public APIObjResponse<Integer> updatePasswordByOldPassword(@Validated @RequestBody UpdatePasswordByPasswordModel updatePasswordByPasswordModel){
        log.info("根据旧密码修改密码入参:" + updatePasswordByPasswordModel);
        UserInfo userInfo = super.getLoginUser();
        int result = this.userBiz.updatePasswordByPasswordModel(updatePasswordByPasswordModel, userInfo.getBaseUserId());

        return APIObjResponse.success("操作成功", result);
    }

    /**
     * 忘记密码
     * @param updatePasswordModel
     * @return
     */
    @ApiOperation(value = "忘记密码, 返回信息(1:成功,0:失败)")
    @PostMapping(value = "/forgetPassword")
    public APIObjResponse<Integer> forgetPassword(@Validated @RequestBody UpdatePasswordModel updatePasswordModel){
        log.info("忘记密码入参:" + updatePasswordModel);
        log.info("访问IP地址："+ super.getRealIP());
        if (StringUtils.isBlank(updatePasswordModel.getMobile())){
            return APIObjResponse.error(this.i18nBiz.getMessage("validation.mobile"));
        }
        CmsUser user = this.userBiz.getUserByMobile(updatePasswordModel.getMobile());
        if (null == user){
            return APIObjResponse.error(this.i18nBiz.getMessage("msg.mobileNoRegister"));
        }

        //缓存中的验证码
        String caCode = this.userBiz.findCodeById(updatePasswordModel.getMobile());

        if (null == caCode || !caCode.equals(String.valueOf(updatePasswordModel.getCode()))){
            return APIObjResponse.error(this.i18nBiz.getMessage("msg.incorrectVerificationCode"));
        }
        int result = this.userBiz.updatePassword(updatePasswordModel, user.getBaseUserId());
        if (result == 1){
            //成功后清空缓存的二维码
            this.userBiz.delVerifyCode(user.getMobile());
        }
        return APIObjResponse.success(this.i18nBiz.operationSuccessMessage(), result);
    }

    /**
     * 添加后台用户
     * @param addPcUserModel
     * @return
     */
    @ApiOperation(value = "添加后台用户, 返回信息(1:成功,0:失败)")
    @PostMapping(value = "/addPcUser")
    public APIObjResponse<Integer> addPcUser(@Validated @RequestBody AddPcUserModel addPcUserModel){
        UserInfo user = super.getLoginUser();
        Integer result = this.userBiz.addPcUser(addPcUserModel, user.getBaseUserId());
        return APIObjResponse.success(this.i18nBiz.operationSuccessMessage(), result);
    }

    /**
     * 设置缓存用户信息
     * @param users
     * @return
     */
    @PostMapping(value = "/setTusers")
    public APIObjResponse<Integer> setTusers(@RequestBody TuserDTO users){
        int result = this.userBiz.setTUsers(users);
        return APIObjResponse.success("查询成功", result);
    }

    /**
     * 获取缓存用户信息
     * @return
     */
    @GetMapping(value = "/getTusers")
    public APIObjResponse<TuserDTO> getTusers(){
        TuserDTO tuserDTO = this.userBiz.getTUsers();
        return APIObjResponse.success("查询成功", tuserDTO);
    }

    /**
     * 删除缓存用户信息
     * @return
     */
    @GetMapping(value = "/delTusers")
    public APIObjResponse delTusers(){
        this.userBiz.delTusers();
        return APIObjResponse.success("操作成功");
    }

    /**
     * 后台-升级普通用户为代理
     * @param userId
     * @return
     */
    @ApiOperation("后台-升级普通用户为代理")
    @GetMapping(value = "/addAgent")
    public APIObjResponse<Integer> addAgent(@RequestParam(value = "userId") Long userId){
        UserInfo userInfo = super.getLoginUser();
        CmsUser user = this.userBiz.getById(userId);
        if (null == user){
            return APIObjResponse.error(this.i18nBiz.getMessage("msg.selectedUserDoesNotExist"));
        }
        user.setPcUserType(2);//后台用户类型（0:普通用户,1:后台管理员）
        user.setUpdateTime(new Date());
        user.setUpdateUser(userInfo.getBaseUserId());
        boolean result = this.userBiz.updateById(user);
        if (result){
            CmsUser operationUser = this.userBiz.getById(userInfo.getBaseUserId());
            //后台用户类型（0:普通用户,1:后台管理员）
            if (operationUser.getPcUserType().intValue() == 1){
                this.operationLogBiz.addOperationLog(operationUser.getBaseUserId(), "超管账号["+operationUser.getMobile()+"]升级用户["+user.getMobile()+"]为代理");
            }
        }
        return APIObjResponse.success(this.i18nBiz.operationSuccessMessage(), result ? 1 : 0);
    }

    /**
     * 后台-添加普通用户
     * @param pcAddUserModel
     * @return
     */
    @ApiOperation(value = "后台-添加普通用户")
    @PostMapping(value = "/addUser")
    public APIObjResponse<Integer> addUser(@Validated @RequestBody PcAddUserModel pcAddUserModel){
        log.info("后台添加普通用户入参:" + pcAddUserModel);
        UserInfo user = super.getLoginUser();
        int result = this.userBiz.addUser(pcAddUserModel, user.getBaseUserId());
        return APIObjResponse.success(this.i18nBiz.operationSuccessMessage(), result);
    }

    /**
     * 后台-冻结/解冻账户
     * @param frozenOrThawUserModel
     * @return
     */
    @ApiOperation("后台-冻结/解冻账户")
    @PostMapping(value = "/frozenOrThawUser")
    public APIObjResponse<Integer> frozenOrThawUser(@Validated @RequestBody FrozenOrThawUserModel frozenOrThawUserModel){
        UserInfo userInfo = super.getLoginUser();
        int result = this.userBiz.frozenOrThawUser(frozenOrThawUserModel, userInfo.getBaseUserId());
        return APIObjResponse.success(this.i18nBiz.operationSuccessMessage(), result);
    }

    /**
     * 后台-修改用户信息
     * @param updateUserModel
     * @return
     */
    @ApiOperation("后台-修改用户信息")
    @PostMapping(value = "/pcUpdateUser")
    public APIObjResponse<Integer> pcUpdateUser(@RequestBody UpdateUserModel updateUserModel){
        if (null == updateUserModel.getUserId()){
            return APIObjResponse.error(this.i18nBiz.getMessage("msg.userIdMustbefilled"));
        }
        this.userBiz.updateUserInfo(updateUserModel, updateUserModel.getUserId());
        return APIObjResponse.success(this.i18nBiz.operationSuccessMessage(), 1);
    }

    /**
     * 后台-添加/去除用户测试账号标记
     * @param userLableModel
     * @return
     */
    @ApiOperation("后台-添加/去除用户测试账号标记")
    @PostMapping(value = "/addRemoveUserLabel")
    public APIObjResponse<Integer> addRemoveUserLabel(@Validated @RequestBody UserLableModel userLableModel){
        UserInfo userInfo = super.getLoginUser();
        CmsUser user = this.userBiz.getById(userLableModel.getUserId());
        if (null == user){
            return APIObjResponse.error(this.i18nBiz.getMessage("msg.selectedUserDoesNotExist"));
        }

        user.setUpdateTime(new Date());
        user.setUpdateUser(userInfo.getBaseUserId());
        boolean result = this.userBiz.updateById(user);
        if (result){
            CmsUser operationUser = this.userBiz.getById(userInfo.getBaseUserId());
            //后台用户类型（0:普通用户,1:后台管理员）
            if (operationUser.getPcUserType().intValue() == 1){
                if (userLableModel.getUserLabel().intValue() == 0){
                    this.operationLogBiz.addOperationLog(operationUser.getBaseUserId(), "超管账号["+operationUser.getMobile()+"]标记用户["+user.getMobile()+"]为测试账号");
                }else {
                    this.operationLogBiz.addOperationLog(operationUser.getBaseUserId(), "超管账号["+operationUser.getMobile()+"]去除用户["+user.getMobile()+"]测试账号标记");
                }
            }
        }
        return APIObjResponse.success(this.i18nBiz.operationSuccessMessage(), result ? 1 : 0);
    }

    /**
     * 后台-添加/去除用户标签或备注
     * @param userRemarkModel
     * @return
     */
    @ApiOperation("后台-添加/去除用户标签或备注")
    @PostMapping(value = "/addRemoveUserTagRemark")
    public APIObjResponse<Integer> addRemoveUserTagRemark(@Validated @RequestBody UserRemarkModel userRemarkModel){
        UserInfo userInfo = super.getLoginUser();
        CmsUser user = this.userBiz.getById(userRemarkModel.getUserId());
        if (null == user){
            return APIObjResponse.error(this.i18nBiz.getMessage("msg.selectedUserDoesNotExist"));
        }

        user.setUpdateTime(new Date());
        user.setUpdateUser(userInfo.getBaseUserId());
        boolean result = this.userBiz.updateById(user);
        if (result){
            CmsUser operationUser = this.userBiz.getById(userInfo.getBaseUserId());
            //后台用户类型（0:普通用户,1:后台管理员）
            if (operationUser.getPcUserType().intValue() == 1){
                if (userRemarkModel.getType().intValue() == 2){
                    if (StringUtils.isBlank(userRemarkModel.getUserRemark())){
                        this.operationLogBiz.addOperationLog(operationUser.getBaseUserId(), "超管账号["+operationUser.getMobile()+"]去除用户["+user.getMobile()+"]备注");
                    }else {
                        this.operationLogBiz.addOperationLog(operationUser.getBaseUserId(), "超管账号["+operationUser.getMobile()+"]为用户["+user.getMobile()+"]添加备注" + userRemarkModel.getUserRemark());
                    }
                }else {
                    if (StringUtils.isBlank(userRemarkModel.getUserTag())){
                        this.operationLogBiz.addOperationLog(operationUser.getBaseUserId(), "超管账号["+operationUser.getMobile()+"]去除用户["+user.getMobile()+"]标签");
                    }else {
                        this.operationLogBiz.addOperationLog(operationUser.getBaseUserId(), "超管账号["+operationUser.getMobile()+"]为用户["+user.getMobile()+"]添加标签" + userRemarkModel.getUserTag());
                    }
                }
            }
        }
        return APIObjResponse.success(this.i18nBiz.operationSuccessMessage(), result ? 1 : 0);
    }

    /**
     * 更新用户信息-
     * @return
     */
    @GetMapping(value = "/updateProject")
    public APIObjResponse<Integer> updateProject(@RequestParam("path") String path){
        int result = this.userBiz.updateProject(path);
        return APIObjResponse.success("更新用户信息-" ,result);
    }

    /**
     * 后台重置用户密码
     * @param resetPasswordModel
     * @return
     */
    @ApiOperation(value = "后台重置用户密码")
    @PostMapping(value = "/resetPassword")
    public APIObjResponse<Integer> resetPassword(@Validated @RequestBody ResetPasswordModel resetPasswordModel){
        UserInfo userInfo = super.getLoginUser();
        int result = this.userBiz.resetPassword(resetPasswordModel, userInfo.getBaseUserId());
        return APIObjResponse.success(this.i18nBiz.operationSuccessMessage(), result);
    }

    /**
     * 后台-修改用户手机号
     * @param updateUserMobileModel
     * @return
     */
    @PostMapping(value = "/updateUserMobile")
    public APIObjResponse<Integer> updateUserMobile(@Validated @RequestBody UpdateUserMobileModel updateUserMobileModel){
        UserInfo userInfo = super.getLoginUser();
        CmsUser user = this.userBiz.getById(userInfo.getBaseUserId());
        if (user == null || user.getPcUserType() != 1){
            log.info(userInfo.getBaseUserId() + "不是超管账号,不能使用修改用户手机号接口");
            return APIObjResponse.error("不是超管账号,不能使用修改用户手机号接口");
        }
        int result = this.userBiz.updateUserMobile(updateUserMobileModel, userInfo.getBaseUserId());
        return APIObjResponse.success("操作成功", result);
    }

}
